package com.ag.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbEventInfect;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbEventInfect entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.ag.bean.TbEventInfect
 * @author MyEclipse Persistence Tools
 */

public class TbEventInfectDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbEventInfectDAO.class);
	// property constants
	public static final String EI_ADDR = "eiAddr";
	public static final String EI_RADIUS = "eiRadius";
	public static final String EI_LONGITUDE = "eiLongitude";
	public static final String EI_LATITUDE = "eiLatitude";
	public static final String EI_SCOPE_DESC = "eiScopeDesc";
	public static final String A = "a";
	public static final String B = "b";
	public static final String C = "c";

	protected void initDao() {
		// do nothing
	}

	public void save(TbEventInfect transientInstance) {
		log.debug("saving TbEventInfect instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbEventInfect persistentInstance) {
		log.debug("deleting TbEventInfect instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbEventInfect findById(java.lang.String id) {
		log.debug("getting TbEventInfect instance with id: " + id);
		try {
			TbEventInfect instance = (TbEventInfect) getHibernateTemplate()
					.get("com.ag.bean.TbEventInfect", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbEventInfect> findByExample(TbEventInfect instance) {
		log.debug("finding TbEventInfect instance by example");
		try {
			List<TbEventInfect> results = (List<TbEventInfect>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbEventInfect instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TbEventInfect as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbEventInfect> findByEiAddr(Object eiAddr) {
		return findByProperty(EI_ADDR, eiAddr);
	}

	public List<TbEventInfect> findByEiRadius(Object eiRadius) {
		return findByProperty(EI_RADIUS, eiRadius);
	}

	public List<TbEventInfect> findByEiLongitude(Object eiLongitude) {
		return findByProperty(EI_LONGITUDE, eiLongitude);
	}

	public List<TbEventInfect> findByEiLatitude(Object eiLatitude) {
		return findByProperty(EI_LATITUDE, eiLatitude);
	}

	public List<TbEventInfect> findByEiScopeDesc(Object eiScopeDesc) {
		return findByProperty(EI_SCOPE_DESC, eiScopeDesc);
	}

	public List<TbEventInfect> findByA(Object a) {
		return findByProperty(A, a);
	}

	public List<TbEventInfect> findByB(Object b) {
		return findByProperty(B, b);
	}

	public List<TbEventInfect> findByC(Object c) {
		return findByProperty(C, c);
	}

	public List findAll() {
		log.debug("finding all TbEventInfect instances");
		try {
			String queryString = "from TbEventInfect";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbEventInfect merge(TbEventInfect detachedInstance) {
		log.debug("merging TbEventInfect instance");
		try {
			TbEventInfect result = (TbEventInfect) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbEventInfect instance) {
		log.debug("attaching dirty TbEventInfect instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbEventInfect instance) {
		log.debug("attaching clean TbEventInfect instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbEventInfectDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TbEventInfectDAO) ctx.getBean("TbEventInfectDAO");
	}
}